package com.shop.api;

import com.shop.feignClient.DiscountClient;
import com.shop.po.R;
import com.shop.user.po.dto.DiscountDto;
import com.shop.user.service.DiscountUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author banxia
 * @since 2023-02-27
 */
@RestController
@RequestMapping("/discountUser")
@CrossOrigin
public class DiscountUserController {

    @Autowired
    private DiscountUserService discountUserService;

    @Autowired
    private DiscountClient discountClient;

    /**
     * 获取当前用于的优惠券信息
     * @param expire:是否已过期
     * @param used：是否已被使用
     * @param notStart:未到使用时间
     * @return
     */
    @GetMapping("/getDiscountDtoList")
    public R getDiscountDtoList(@RequestParam(required = false) Boolean expire,
                                @RequestParam(required = false) Boolean used,
                                @RequestParam(required = false) Boolean notStart){
        List<DiscountDto> list = discountUserService.getDiscountDtoList(expire, used, notStart);
        return R.ok("成功获取当前用户的优惠券信息").data("list",list);
    }


    @PostMapping("/robDiscount/{discountId}")
    public R robDiscount(@PathVariable("discountId") Long discountId){
        boolean b = discountUserService.robDiscount(discountId);
        if (b) {
            return R.ok("成功领情到该优惠券");
        }else{
            return R.error("领情优惠券失败~~请重试");
        }
    }

}

